package _5_multithread._1_basic;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

public class _30_ThreadLocal {

    private static ThreadLocal<Map<String, Integer>> threadLocal = new ThreadLocal<Map<String, Integer>>() {
        @Override
        protected Map<String, Integer> initialValue() {
            HashMap<String, Integer> hashMap = new HashMap<>();
            hashMap.put("test", new Random().nextInt());
            return hashMap;
        }
    };

    public static void main(String[] args) {
        new Thread(() -> {
            Map<String, Integer> map = threadLocal.get();
            System.out.println(map);
        },"myThread").start();
        new Thread(() -> {
            Map<String, Integer> map = threadLocal.get();
            System.out.println(map);
        },"myThread2").start();
    }

}
